//
//  StatusCellFootView.swift
//  Weibo10
//
//  Created by Leon on 15/10/19.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit

class StatusCellFootView: UIView {
    
    var viewModel: StatusViewModel? {
        didSet {
            // 转发数
            transmitButton.setTitle(viewModel?.repostsText, forState: .Normal)
            // 评论数
            commentButton.setTitle(viewModel?.commentsText, forState: .Normal)
            // 表态数
            likeButton.setTitle(viewModel?.attitudesText, forState: .Normal)
        }
    }

    ///  构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    /// 转发按钮
    private lazy var transmitButton: UIButton = UIButton(title: "转发", imageName: "timeline_icon_retweet", backImageName: "timeline_card_middle_background", color: UIColor.darkGrayColor(), fontSize: 15)
    /// 评论按钮
    private lazy var commentButton: UIButton = UIButton(title: "评论", imageName: "timeline_icon_comment", backImageName: "timeline_card_middle_background", color: UIColor.darkGrayColor(), fontSize: 15)
    /// 点赞按钮
    private lazy var likeButton: UIButton = UIButton(title: "", imageName: "timeline_icon_unlike", backImageName: "timeline_card_middle_background", color: UIColor.darkGrayColor(), fontSize: 15)
    
}

// MARK: - 设置界面
extension StatusCellFootView {
    
    private func setupUI() {
        // 0 背景图片
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        let sep1 = separatorLine()
        let sep2 = separatorLine()
        // 1 添加控件
        addSubview(transmitButton)
        addSubview(commentButton)
        addSubview(likeButton)
        addSubview(sep1)
        addSubview(sep2)
        
        // 2 自动布局
        transmitButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.width.equalTo(commentButton.snp_width)
            make.height.equalTo(commentButton.snp_height)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(transmitButton.snp_right)
            make.bottom.equalTo(self.snp_bottom)
            make.right.equalTo(likeButton.snp_left)
        }
        likeButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.width.equalTo(commentButton.snp_width)
            make.height.equalTo(commentButton.snp_height)
        }
        
        sep1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.snp_centerY)
            make.left.equalTo(transmitButton.snp_right).offset(-1)
            make.width.equalTo(2)
            make.height.equalTo(self.snp_height).multipliedBy(0.7)
        }
        sep2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.snp_centerY)
            make.left.equalTo(commentButton.snp_right).offset(-1)
            make.width.equalTo(2)
            make.height.equalTo(self.snp_height).multipliedBy(0.7)
        }
    }
    
    ///  分割线
    func separatorLine() -> UIImageView {
        return UIImageView(imageName: "timeline_card_bottom_line_highlighted")
    }
}


